<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="template/adminBase.xhtml">

    <ui:define name="adminContent">
        <h:form>
            <h:dataTable name="movieTable" value="#{movieController.movies}" var="movie"
                         styleClass="cinemaTable"
                         headerClass="cinemaTableHeader"
                         rowClasses="cinemaTableOddRow,cinemaTableEvenRow">
                <h:column>
                    <f:facet name="header">Title</f:facet>
                    <h:inputText id="newTitle" label="Title" value="#{movie.title}"
                                 size="10"
                                 rendered="#{movieController.canEdit.get(movieController.movies.indexOf(movie))}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    <h:outputText value="#{movie.title}"
                                  rendered="#{not movieController.canEdit.get(movieController.movies.indexOf(movie))}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Length</f:facet>
                    <h:inputText id="newLength" label="Length" value="#{movie.length}"
                                 size="10"
                                 rendered="#{movieController.canEdit.get(movieController.movies.indexOf(movie))}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    <h:outputText value="#{movie.length}"
                                  rendered="#{not movieController.canEdit.get(movieController.movies.indexOf(movie))}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Description</f:facet>
                    <h:inputText id="newDesc" label="Description" value="#{movie.description}"
                                 size="10"
                                 rendered="#{movieController.canEdit.get(movieController.movies.indexOf(movie))}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    <h:outputText value="#{movie.description}"
                                  rendered="#{not movieController.canEdit.get(movieController.movies.indexOf(movie))}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Edit</f:facet>
                    <h:commandButton class="adminButton" value="Edit"
                                     action="#{movieController.editMovie}"
                                     rendered="#{not movieController.canEdit.get(movieController.movies.indexOf(movie))}">
                        <f:setPropertyActionListener
                                target="#{movieController.movie}" value="#{movie}"/>
                    </h:commandButton>
                    <h:commandButton class="adminButton" value="Save"
                                     action="#{movieController.saveMovie}"
                                     rendered="#{movieController.canEdit.get(movieController.movies.indexOf(movie))}">
                        <f:setPropertyActionListener
                                target="#{movieController.movie}" value="#{movie}"/>
                    </h:commandButton>
                </h:column>
                <h:column>
                    <f:facet name="header">Delete</f:facet>
                    <h:commandButton class="adminButton" value="Delete"
                                     action="#{movieController.deleteMovie}">
                        <f:setPropertyActionListener
                                target="#{movieController.movie}" value="#{movie}"/>
                    </h:commandButton>
                </h:column>
            </h:dataTable>
            <h:message for="newTitle" style="color:red"/>
            <h:message for="newLength" style="color:red"/>
            <h:message for="newDesc" style="color:red"/>
        </h:form>
        <h:form>
            <h3>Add Movie</h3>
            <table>
                <tr>
                    <td>Title:</td>
                    <td><h:inputText id="titleInput" label="Title" class="inputText"
                                     size="20" value="#{movieController.title}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    </td>
                </tr>
                <tr>
                    <td>Length:</td>
                    <td><h:inputText id="lengthInput" label="Length" class="inputText"
                                     size="10" value="#{movieController.length}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    </td>
                </tr>
                <tr>
                    <td>Description:</td>
                    <td><h:inputText id="descInput" label="Description" class="inputText"
                                     size="40" value="#{movieController.description}">
                        <f:validateLength minimum="2"/>
                    </h:inputText>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><h:commandButton value="Add Movie" class="adminButton"
                                         action="#{movieController.addMovie}"/></td>
                </tr>
            </table>
        </h:form>
    </ui:define>
</ui:composition>
</html>